package com.example.service.impl;

import com.example.dao.OperationMapper;
import com.example.entity.*;
import com.example.service.OperationService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class OperationServiceImpl implements OperationService {
    private final OperationMapper mapper;
    private final SqlSession sqlSession;

    public OperationServiceImpl(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
        this.mapper = sqlSession.getMapper(OperationMapper.class);
    }
    @Override
    public void commit() {
        sqlSession.commit();
    }
    @Override
    public void rollback() {
        sqlSession.rollback();
    }
    //机票操作
    //退票
    @Override
    public Ticket getTicketById(int ticketId) {
        return mapper.getTicketById(ticketId);
    }
    @Override
    public int cancelTicket(int ticketId) {
        return mapper.cancelTicket(ticketId);
    }
    @Override
    public int getPassengersByOrderId(int orderId) {
        return mapper.getPassengersByOrderId(orderId);
    }
    @Override
    public int reducePassengerPriceOrder(int orderId, double price) {
        return mapper.reducePassengerPriceOrder(orderId, price);
    }
    @Override
    public int cancelOrder(int orderId, String cancelDate) {
        return mapper.cancelOrder(orderId, cancelDate);
    }
    @Override
    public int refundOrder(int orderId, String refundDate) {
        return mapper.refundOrder(orderId, refundDate);
    }
    @Override
    public int addEconomySpaceByFid(int f_id) {
        return mapper.addEconomySpaceByFid(f_id);
    }
    @Override
    public int addBusinessSpaceByFid(int f_id) {
        return mapper.addBusinessSpaceByFid(f_id);
    }
    @Override
    public int addFirstSpaceByFid(int f_id) {
        return mapper.addFirstSpaceByFid(f_id);
    }
    @Override
    public int reducePassengerOrderNumByPassengerId(String ID_type,String ID_card) {
        return mapper.reducePassengerOrderNumByPassengerId(ID_type, ID_card);
    }
    @Override
    public int refundTicket(int t_id) {
        return mapper.refundTicket(t_id);
    }
    @Override
    public int setOrderIdinTicket(int t_id) {
        return mapper.setOrderIdinTicket(t_id);
    }
    //再次预定
    @Override
    public Flight getFlightById(int f_id) {
        return mapper.getFlightById(f_id);
    }
    //改签
    @Override
    public Order getOrderById(int orderId) {
        return mapper.getOrderById(orderId);
    }
    @Override
    public User getUserById(int userId) {
        return mapper.getUserById(userId);
    }
    @Override
    public FlightStatus getFlightStatusById(int f_id) {
        return mapper.getFlightStatusById(f_id);
    }
    @Override
    public int refundMoneyByUserIDtypeAndIDcard(String ID_type, String ID_card, double money) {
        return mapper.refundMoneyByUserIDtypeAndIDcard(ID_type, ID_card, money);
    }
    @Override
    public int deleteTicket(int t_id) {
        return mapper.deleteTicket(t_id);
    }
    @Override
    public int reduceEconomySpaceByFid(int f_id) {
        return mapper.reduceEconomySpaceByFid(f_id);
    }
    @Override
    public int reduceBusinessSpaceByFid(int f_id) {
        return mapper.reduceBusinessSpaceByFid(f_id);
    }
    @Override
    public int reduceFirstSpaceByFid(int f_id) {
        return mapper.reduceFirstSpaceByFid(f_id);
    }
    @Override
    public int addOrder(int userId, String user_name, int flightNo, String airline, String date, String from, String to, String departure, String arrival, double price, int passengers, String status, String statusText, String paymentMethod, String paymentDate) {
        return mapper.addOrder(userId, user_name, flightNo, airline, date, from, to, departure, arrival, price, passengers, status, statusText, paymentMethod, paymentDate);
    }
    @Override
    public int getLastOrderId() {
        return mapper.getLastOrderId();
    }
    @Override
    public int addTicket(int orderId, int passengerId, String passengerName, String passengerType, int flightNo, String date, double price, String seatType, String status, String statusText) {
        return mapper.addTicket(orderId, passengerId, passengerName, passengerType, flightNo, date, price, seatType, status, statusText);
    }
    @Override
    public int deleteOrder(int o_id) {
        return mapper.deleteOrder(o_id);
    }
    @Override
    public int reduceMoneyByUserIDtypeAndIDcard(String ID_type, String ID_card, double money) {
        return mapper.reduceMoneyByUserIDtypeAndIDcard(ID_type, ID_card, money);
    }

    //订单操作
    @Override
    public List<Ticket> getTicketsByOrderId(int o_id) {
        return mapper.getTicketsByOrderId(o_id);
    }
    @Override
    public int scheduledTicketStatus(int o_id) {
        return mapper.scheduledTicketStatus(o_id);
    }
    @Override
    public int payOrder(int orderId, String paymentDate, String paymentMethod) {
        return mapper.payOrder(orderId, paymentDate, paymentMethod);
    }

    //管理员
    @Override
    public int cancelTicketByOrderId(int o_id) {
        return mapper.cancelTicketByOrderId(o_id);
    }
    @Override
    public int payOrderNoDate(int orderId) {
        return mapper.payOrderNoDate(orderId);
    }
    //延误
    @Override
    public int delayFlightStatusByFlightId(int f_id) {
        return mapper.delayFlightStatusByFlightId(f_id);
    }
    @Override
    public int delayTicketByFlightId(int f_id) {
        return mapper.delayTicketByFlightId(f_id);
    }
    @Override
    public List<Ticket> getTicketsByFlightId(int f_id) {
        return mapper.getTicketsByFlightId(f_id);
    }
    @Override
    public String getEmailByPassengerId(int passenger_id) {
        return mapper.getEmailByPassengerId(passenger_id);
    }

    //删除
    @Override
    public int deleteFlight(int f_id) {
        return mapper.deleteFlight(f_id);
    }
    @Override
    public int deleteFlightStatus(int f_id) {
        return mapper.deleteFlightStatus(f_id);
    }
    @Override
    public int deleteOrderByFlightId(int f_id) {
        return mapper.deleteOrderByFlightId(f_id);
    }
    @Override
    public int deletePlane(int p_id) {
        return mapper.deletePlane(p_id);
    }
    @Override
    public int deleteTicketByFlightId(int f_id) {
        return mapper.deleteTicketByFlightId(f_id);
    }
    //编辑
    @Override
    public FlightWithStatus getFlightWithStatus(int f_id) {
        return mapper.getFlightWithStatus(f_id);
    }
    @Override
    public int editFlight(int f_id, String gate, String departure_date, String arrival_date, String departure_time, String arrival_time, double distance, double economy_price, double business_price, double first_price, int baggage_limit, String meal_money, String meal) {
        return mapper.editFlight(f_id, gate, departure_date, arrival_date, departure_time, arrival_time, distance, economy_price, business_price, first_price, baggage_limit, meal_money, meal);
    }
    @Override
    public int editFlightStatus(int f_id, String status, String captain, String assistant_captain, String chief_attendant, int flight_crew_num) {
        return mapper.editFlightStatus(f_id, status, captain, assistant_captain, chief_attendant, flight_crew_num);
    }

    //起飞
    @Override
    public int flightStart(int f_id) {
        return mapper.flightStart(f_id);
    }
    @Override
    public void ticketFlightStart(int f_id) {
        mapper.ticketFlightStart(f_id);
    }
    @Override
    public void orderFlightStart(int f_id) {
        mapper.orderFlightStart(f_id);
    }
    //到达
    @Override
    public int flightArrive(int f_id) {
        return mapper.flightArrive(f_id);
    }
}
